﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GameTank
{
    class TimeCounter
    {
        DateTime _startime;
        TimeSpan _duration;

        public TimeSpan Duration
        {
            get { return _duration; }
            set { _duration = value; }
        }

        float _timeCount;

        public float TimeoCounted
        {
            get { return _timeCount; }
            set { _timeCount = value; }
        }

        bool _ready = false;

        public bool Ready
        {
            get 
            {
                if (!_ready)
                {
                    _duration = DateTime.Now - _startime;
                    if (_duration.TotalMilliseconds >= _timeCount)
                    {
                       _ready = true;
                    }
                }
                return _ready;
            }
            set { _ready = value; }
        }

        public void count(float timeCount)
        {
            _ready = false;
            _startime = DateTime.Now;
            _timeCount = timeCount;
        }

        public void recount(float timeCount, TimeSpan duration)
        {
            _startime = DateTime.Now - duration;
            _timeCount = timeCount;
            _duration = duration;
        }

        public void recount()
        {
            _startime = DateTime.Now;
            _ready = false;
        }

        public void running()
        {
            _duration = DateTime.Now - _startime;
        }

        public void reset()
        {
            _ready = false;
        }
    }
}
